package com.gjm.demo.LoginController;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class LoginController {

    @RequestMapping("/login")
    public boolean login(String userName, String password, HttpSession session) {
//        System.out.println(userName);
//        System.out.println(password);
        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
//            System.out.println(1);
            return false;
        }
        if (("adminGoogle".equals(userName) || "adminPostman".equals(userName)) && "123456".equals(password)) {
            session.setAttribute("userName", userName);
//            System.out.println(2);
            return true;
        }
//        System.out.println(3);
        return false;
    }

    @RequestMapping("/getLoginUser")
    public String getUserName(HttpSession session) {
        return (String)session.getAttribute("userName");
    }
}
